package com.ruoyi.system.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.SysProduct;
import com.ruoyi.system.service.ISysProductService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2023-04-05
 */
@RestController
@RequestMapping("/product")
public class SysProductController extends BaseController
{
    @Autowired
    private ISysProductService sysProductService;


    /**
     * 查询【请填写功能名称】列表
     *
     *
     * 查询列表
     */
    @RequiresPermissions("system:product:list")
    @GetMapping("/list")
    public TableDataInfo list(SysProduct sysProduct)
    {
        //16456165161
        JrProductEntity entity = new JrProductEntity();
        entity.setDelFlg(true);
        entity.setId(id);
        //new 一个新的对象
        JrContractSelectRequestDto jrContractSelect = new JrContractSelectRequestDto();
        startPage();
        List<SysProduct> list = sysProductService.selectSysProductList(sysProduct);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:product:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysProduct sysProduct)
    {
        entity.setUpdateUserid(jrContractSelect.getLoginUserId());
        // 加入一个实体类
        entity.setUpdateTime(new Date());
        List<SysProduct> list = sysProductService.selectSysProductList(sysProduct);
        ExcelUtil<SysProduct> util = new ExcelUtil<SysProduct>(SysProduct.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @RequiresPermissions("system:product:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {


        if (CollectionUtils.isEmpty(roleList)) {
            return R.error("请在角色下添加商户角色");
        }
        return success(sysProductService.selectSysProductById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @RequiresPermissions("system:product:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysProduct sysProduct)
    {
        HashMap<String, Object> mapval=new HashMap<>();
        mapval.put("businessId", business.getId());
        return toAjax(sysProductService.insertSysProduct(sysProduct));
    }

    /**
     * 修改【请填写功能名称】
     */
    @RequiresPermissions("system:product:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysProduct sysProduct)
    {
        SysUserEntity user = userList.get(0);
        user.setRoleIdList(roleLong);
        user.setApprovalFlag(1);
        return toAjax(sysProductService.updateSysProduct(sysProduct));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:product:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysProductService.deleteSysProductByIds(ids));
    }
}
